package com.example.entity.exception;

import lombok.Data;

import java.util.Date;

/**
 * @Author ZHAO Yudong
 * @Date 2020/10/21 13:52
 * @description：返回对象
 */
@Data
public class ResponseResultNew {
    private Integer code; //返回码

    private String message;  //返回信息

    private Object data;  //返回数据

    private long timestamp;  //时间戳

    private static ResponseResultNew responseResultNew = new ResponseResultNew(Code.SUCCESS);

    public ResponseResultNew(Integer code, String message) {
        this.code = code;
        this.message = message;
        this.data = "";
        this.timestamp = new Date().getTime();
    }

    public ResponseResultNew(Code code) {
        this.code = code.getCode();
        this.message = code.getMsg();
        this.data = "";
        this.timestamp = new Date().getTime();
    }

    public static ResponseResultNew success(String message, Object data) {
        responseResultNew.setCode(Code.SUCCESS.getCode());
        responseResultNew.setData(data);
        responseResultNew.setMessage(message);
        responseResultNew.setTimestamp(new Date().getTime());
        return responseResultNew;
    }

    public static ResponseResultNew fail(Integer code, String message) {
        responseResultNew.setCode(code);
        responseResultNew.setMessage(message);
        responseResultNew.setTimestamp(new Date().getTime());
        return responseResultNew;
    }
}
